package vip.meet.handler;

import vip.meet.type.EnableOrDisableStatus;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class EnableOrDisableStatusHandler implements TypeHandler<EnableOrDisableStatus> {

    @Override
    public void setParameter(PreparedStatement ps, int i, EnableOrDisableStatus enableOrDisableStatus, JdbcType jdbcType) throws SQLException {
        ps.setInt(i, enableOrDisableStatus == null ? EnableOrDisableStatus.ENABLE.getId() : enableOrDisableStatus.getId());
    }

    @Override
    public EnableOrDisableStatus getResult(ResultSet resultSet, String columnName) throws SQLException {
        return EnableOrDisableStatus.getInstance(resultSet.getInt(columnName));
    }

    @Override
    public EnableOrDisableStatus getResult(ResultSet resultSet, int columnIndex) throws SQLException {
        return EnableOrDisableStatus.getInstance(resultSet.getInt(columnIndex));
    }

    @Override
    public EnableOrDisableStatus getResult(CallableStatement callableStatement, int columnIndex) throws SQLException {
        return EnableOrDisableStatus.getInstance(callableStatement.getInt(columnIndex));
    }


}
